import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";

import path from "path";

// 引入vanui组件自动导入
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { VantResolver } from "@vant/auto-import-resolver";

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [VantResolver()],
    }),
    Components({
      resolvers: [VantResolver()],
    }),
  ],
  // 配置根路径
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src"),
    },
  },
  // 解决前后端跨域问题
  // 添加 server 配置
  server: {
    // 设置代理
    proxy: {
      "/api": {
        target: "http://localhost:3000", // 目标服务器地址
        changeOrigin: true, // 是否改变请求头中的 Origin，默认为 false
        rewrite: (path) => path.replace(/^\/api/, "/api"), // 重写路径
      },
    },
  },
});
